﻿using System;
using Portal.Core.Utils;
using Portal.Data.Entity;

public partial class jRating_Rating : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        dynamic jdata = new DynamicJsonObject();
        int bid, rate;
        int.TryParse(Request["idBox"], out bid);
        int.TryParse(Request["rate"], out rate);
        if (bid > 0 && rate > 0)
        {
            var b = Book.FindByPrimaryKey(bid);
            if (b != null)
            {
                b.RateAverage = Math.Round((b.RateAverage * b.RateTotal + rate) / (b.RateTotal + 1), 1);
                b.RateTotal++;
                b.UpdateOnly();

                jdata.total = b.RateTotal;
                jdata.average = b.RateAverage;
            }
        }
        Response.Write(jdata.ToString());
        Response.End();
    }
}